package com.jose.photogallery.domain;

import java.util.Date;
import java.util.List;

import javax.persistence.Id;

import com.googlecode.objectify.annotation.Indexed;

public class Photo {
	/*
	 * Key, Blobstore key for the image
	 */
	@Id String blobKey;
	String user;
	String imageURL;
	int height;
	int width;
	String caption;
	List<String> tags;
	String description;
	@Indexed Date uploadDate;
	@Indexed Date updateDate;
	String privacy;
	float rating;
	int cumulative;
	int votes;
	
	public Photo() {}
	
	public Photo(String user, String blobKey, String imageURL, int height, int width, String caption, List<String> tags,
			String description, Date uploadDate, String privacy) {
		super();
		this.user = user;
		this.blobKey = blobKey;
		this.imageURL = imageURL;
		this.height = height;
		this.width = width;
		this.caption = caption;
		this.tags = tags;
		this.description = description;
		this.uploadDate = uploadDate;
		this.privacy = privacy;
		this.rating = 0;
		this.cumulative = 0;
		this.votes = 0;
	}
	
	public void updateRating(int vote){
		this.cumulative += vote;
		this.votes += 1;
		this.rating = this.cumulative / this.votes;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public String getCaption() {
		return caption;
	}

	public void setCaption(String caption) {
		this.caption = caption;
	}

	public String getImageURL() {
		return imageURL;
	}
	
	public String getImageURLPreview() {
		return imageURL + "=s300";
	}
	
	public String getImageURLResize() {
		return imageURL + "=s700";
	}
	
	public String getImageURLThumb(){
		return imageURL + "=s200";
	}

	public void setImageURL(String imageURL) {
		this.imageURL = imageURL;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getBlobKey() {
		return blobKey;
	}

	public void setBlobKey(String blobKey) {
		this.blobKey = blobKey;
	}

	public List<String> getTags() {
		return tags;
	}
	
	public String getTagsString() {
		/*
		 * Returns a String with tags separated by commas
		 * Ex: a, b, c
		 */
		StringBuilder str = new StringBuilder();
	    for(String string : this.tags) {
	    	str.append(string);
	    	str.append(", ");
	    }
	    return str.substring(0, str.length() - 2) ;
	}

	public void setTags(List<String> tags) {
		this.tags = tags;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getUploadDate() {
		return uploadDate;
	}

	public void setUploadDate(Date uploadDate) {
		this.uploadDate = uploadDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public String getPrivacy() {
		return privacy;
	}

	public void setPrivacy(String privacy) {
		this.privacy = privacy;
	}

	public float getRating() {
		return rating;
	}

	public void setRating(float rating) {
		this.rating = rating;
	}

	public int getCumulative() {
		return cumulative;
	}

	public void setCumulative(int cumulative) {
		this.cumulative = cumulative;
	}

	public int getVotes() {
		return votes;
	}

	public void setVotes(int votes) {
		this.votes = votes;
	}
	
	
}
